package cn.aoyu.test.controller;

import cn.aoyu.test.bean.user.User;
import cn.aoyu.test.service.user.UserService;
import cn.aoyu.test.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName: UserController
 * @Auther: xww
 * @Date: 2019/5/17 0017 17:49
 * @Description:
 */
@Controller
@RequestMapping("/test/user")
public class UserController {


	@Autowired
	private UserService userService;

	/**
	 * 添加用户
	 *
	 * @param typeName
	 * @return
	 */
	@RequestMapping(value = "/addUser", method = {RequestMethod.POST})
	public void addUser(@RequestBody User user) {
		User userDetail = new User();
		userDetail.setAge(1);
		userDetail.setName("hj i love u");
		userDetail.setSex("0");
		userService.addUser(userDetail);
	}

	/**
	 * 获取用户列表
	 *
	 * @param typeName
	 * @return
	 */
	@RequestMapping(value = "/getUserById", method = {RequestMethod.GET})
	public void selectUserAll(@RequestParam(value = "userId", required = true) Integer userId,
							  HttpServletRequest request, HttpServletResponse response) {
		User user = userService.getUser(userId);
		ResponseUtil.response(request, response, user);
	}


}
